import javax.servlet.*;
import java.io.IOException;
import java.io.PrintWriter;

public class PrimitiveServlet implements Servlet {

  @Override
  public void init(ServletConfig config) throws ServletException {
    System.out.println("INFO  init  ,  config==>  " + config.getServletName() ) ;
  }

  @Override
  public void service(ServletRequest request, ServletResponse response) throws ServletException, IOException {
    System.out.println("INFO  from service ,  request==> "  + request.getClass().getCanonicalName());
    PrintWriter out = response.getWriter();
    String header = "HTTP/1.1 200 OK\r\n" +
            "Content-Type: text/html\r\n" +
            "Content-Length: " + ("<h1>Hello  this is "+this.getClass().getCanonicalName()+"</h1>").getBytes().length + "\r\n" +
            "\r\n" ;
    out.write(header);
    out.write("<h1>Hello  this is "+this.getClass().getCanonicalName()+"</h1>");
    out.flush();
  }

  @Override
  public void destroy() {
    System.out.println("destroy");
  }

  @Override
  public String getServletInfo() {
    return null;
  }
  @Override
  public ServletConfig getServletConfig() {
    return null;
  }

}
